<template>
  <div>
    <el-card shadow="hover" class="box-card">
      <el-form ref="form" :model="searchForm" label-width="100px">
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="姓名：">
              <el-input v-model="searchForm.name" placeholder="请输入姓名"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="时间范围：">
              <el-date-picker
                v-model="searchForm.time"
                type="month"
                :clearable="false"
                value-format="yyyy-MM-dd"
                placeholder="选择月份"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <div class="">
              <el-button type="primary" @click="getList(1)">查询</el-button>
              <el-button type="info" @click="reset">重置</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <el-card shadow="hover" class="box-card">
      <el-table :data="tableData" border stripe style="width: 100%">
        <el-table-column prop="fullName" label="姓名" align="center"> </el-table-column>
        <el-table-column prop="present" label="出勤天数" align="center"> </el-table-column>
        <el-table-column prop="beLate" label="迟到次数" align="center"> </el-table-column>
        <el-table-column prop="askForLeave" label="请假天数" align="center"> </el-table-column>
        <el-table-column prop="leaveEarly" label="早退次数" align="center"> </el-table-column>
        <el-table-column fixed="right" label="操作" align="center">
          <template slot-scope="scope">
            <el-button @click="detail(scope.row)" type="primary" size="small">详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        class="pageBox"
        background
        layout="prev, pager, next"
        :current-page="currentPage"
        :total="pageTotal"
        @current-change="getList"
        @prev-click="getList"
        @next-click="getList"
      ></el-pagination>
    </el-card>
    <Detail ref="detail" :list-data="listData" :time="searchForm.time" />
  </div>
</template>

<script>
import * as api from '@/api/project'
import Detail from './detail.vue'
export default {
  data() {
    return {
      // 筛选条件
      searchForm: {
        name: '',
        time: '',
      },
      pattern: 'pie',
      // 表格
      tableData: [],
      // 分页
      currentPage: 1,
      pageTotal: 0,
      // 带入详情数据
      listData: {},
    }
  },
  components: {
    Detail,
  },
  created() {
    let date = new Date()
    let year = date.getFullYear()
    let month = date.getMonth() + 1
    month = month > 9 ? month : '0' + month
    this.searchForm.time = year + '-' + month + '-01'
    this.getList(1)
  },
  methods: {
    // 获取列表
    getList(e) {
      this.currentPage = e
      let data = {
        fullName: this.searchForm.name,
        pageNo: e,
        pageSize: 10,
        queryDate: this.searchForm.time,
      }
      api.allAttendance(data).then(res => {
        if (res.code == '200') {
          this.pageTotal = res.data.total
          this.tableData = res.data.attendanceRecordVOList
        }
      })
    },
    // 打开详情
    detail(e) {
      this.$refs.detail.drawer = true
      this.listData = e
    },
    // 选择角色
    roleSelect(item) {},
    // 重置
    reset() {
      this.getList(1)
      this.searchForm.name = ''
    },
  },
}
</script>

<style lang="scss" scoped>
.box-card {
  margin-bottom: 10px;
}
.selectBox {
  width: 100%;
}
.pageBox {
  margin-top: 10px;
  text-align: center;
}
</style>
